<?php
/**
 * Created by PhpStorm.
 * User: xiaomeng
 * Date: 17-9-14
 * Time: 下午3:39
 */

namespace app\websocket\controller;

use swf\core\Controller;
use swf\socket\OperaFd;

class Chat extends Controller
{
    private $allow_msg = ['textIndex','emojiIndex'];

    /**
     * 发送文本内容
     */
    public function sendMsg()
    {
        $reqData = $this->reqData;
        //参数
        $fd = $this->frame->fd;
        //判断发送的内容是否正确
        $reqKeys = array_keys($reqData);
        $res = array_intersect($reqKeys,$this->allow_msg);
        if(empty($res))
        {
            return $this->send('error',[],10);
        }
        $data['fd'] = $fd;
        $data['sendMsg'] = $reqData;
        $this->server->task(json_encode(['cmd'=>'sendMsg','data'=>$data]));
        return true;
    }
}